//
//  RainWebViewJSObject.m
//  jSCoreTest
//
//  Created by rain on 2018/6/27.
//  Copyright © 2018年 company. All rights reserved.
//

#import "RainWebViewJSObject.h"

static NSString *const rainJSCoreNativeObjectName = @"native";
static RainWebViewJSObject *shareWebJSObject = nil;

@implementation RainWebViewJSObject

+ (instancetype)shareInstance {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareWebJSObject = [[RainWebViewJSObject alloc]init];
    });
    return shareWebJSObject;
}

+ (instancetype)allocWithZone:(struct _NSZone *)zone {
    @synchronized (self) {
        if (shareWebJSObject == nil) {
            shareWebJSObject = [super allocWithZone:zone];
            return shareWebJSObject;
        }
    }
    return shareWebJSObject;
}


#pragma mark-- RainWebViewJSObjectMethodHeaderProtocol

- (void)registerExceptionHandlerForContext:(JSContext *)context {
    context.exceptionHandler = ^(JSContext *ctx, JSValue *exception) {
        
        NSLog(@"js exception is %@",exception.description);
        ctx.exception = exception;
        
    };
}

- (void)registerObjectNameForContext:(JSContext *)context {
    context[rainJSCoreNativeObjectName] = self;//把self当做对jscontext对方开放的对象
}


#pragma mark-- RainJSExportProtocol

- (void)debugLog:(NSString *)message {
    
#ifdef DEBUG
    
    NSLog(@"%@",message);
    
#endif
    
}

- (void)callInterface:(NSString *)interface parameters:(NSString *)jsonStr {
    
    NSLog(@"interface %@  jsonStr %@",interface,jsonStr);
    
}


@end
